{extend name="base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">课程管理</li>
                <li class=""><a href="{:url('admin/dp/course_add')}">添加课程</a></li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="">
                        <div class="layui-form-item" style="margin-bottom: 10px;">
    <div class="layui-inline">
        <input type="text" name="name" placeholder="请输入课程名称" value="{$name}" class="layui-input">
    </div>
    <div class="layui-inline" style="margin-left: 10px;">
    <a href="{:url('admin/dp/export_course')}" class="layui-btn layui-btn-normal">导出课程</a>
</div>
    <div class="layui-inline">
        <select name="category_id">
            <option value="">全部分类</option>
            {foreach name="categories" item="cat"}
                <option value="{$cat.id}" {if $cat.id == $category_id}selected{/if}>{$cat.name}</option>
            {/foreach}
        </select>
    </div>
    <div class="layui-inline">
    <select name="status">
        <option value="">全部状态</option>
        <option value="0" {if $status==='0'}selected{/if}>未上课</option>
        <option value="1" {if $status==='1'}selected{/if}>已上课</option>
        <option value="2" {if $status==='2'}selected{/if}>已取消</option>
    </select>
</div>
    <div class="layui-inline">
        <button class="layui-btn" lay-submit>搜索</button>
    </div>
</div>
                        <table class="layui-table" lay-size="sm">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>课程名</th>
                                <th>分类</th>
                                <th>课程专家</th>
                                <th>课程时间</th>
                                <th>课程介绍</th>
                                 <th>最大预约人数</th>
                                  <th>已预约人数</th>
                                  <th>状态</th>
                                <th style="width: 120px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="courses" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.category_name}</td>
                                <td>{$vo.expert_name}</td>
                                <td>{$vo.course_time}</td>
                                <td>{$vo.desc}</td>
                                 <td>{$vo.max_number}</td>
                                <td>{$vo.booked}</td>
                                <td>
    {if $vo.status == 0}
        <span style="color: #1E9FFF;">未上课</span>
    {elseif $vo.status == 1}
        <span style="color: green;">已上课</span>
    {elseif $vo.status == 2}
        <span style="color: gray;">已取消</span>
    {/if}
</td>
                                <td>
                                    <div class="layui-btn-group">
                                        <a href="{:url('admin/dp/course_edit',['id'=>$vo.id])}" class="layui-btn layui-btn-sm" title="编辑"><i class="layui-icon">&#xe642;</i></a>
                                        <!--<a href="{:url('admin/dp/course_delete',['id'=>$vo.id])}" class="layui-btn layui-btn-sm ajax-delete" title="删除"><i class="layui-icon">&#xe640;</i></a>-->
                                        <a href="{:url('admin/dp/course_cancel',['id'=>$vo.id])}" class="layui-btn layui-btn-sm ajax-cancel" title="取消课程"><i class="layui-icon">&#x1006;</i></a>

                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer','form'], function(){
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        $('.ajax-cancel').on('click', function () {
    var _href = $(this).attr('href');
    layer.open({
        shade: false,
        content: '确定取消该课程？',
        btn: ['确定', '取消'],
        yes: function (index) {
            $.ajax({
                url: _href,
                type: "get",
                success: function (info) {
                    if (info.code === 1) {
                        window.location.reload()
                    }
                    layer.msg(info.msg);
                }
            });
            layer.close(index);
        }
    });

    return false;
});
        $('.ajax-delete').on('click', function () {
            var _href = $(this).attr('href');
            layer.open({
                shade: false,
                content: '确定删除？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _href,
                        type: "get",
                        success: function (info) {
                            if (info.code === 1) {
                                window.location.reload()
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });
    });
</script>
{/block}
